package com.mathdroid.model.encounters;

import java.io.Serializable;

/**
 * This contains the encounter settings.
 */
public final class EncounterTemplate implements Serializable {

	/**
	 * Generated UID.
	 */
	private static final long serialVersionUID = -6824277202727687499L;
	
	/**
	 * The name of the encounter template.
	 */
	private String name = null;
	
	/**
	 * The encounter duration.
	 */
	private double durationMs = 0;
	
	/**
	 * Create an encounter template.
	 * @param n Name.
	 */
	public EncounterTemplate(final String n) {
		this.name = n;
	}
	
	@Override
	public String toString() {
		return this.name;
	}

	/**
	 * Sets the name of this encounter template.
	 * @param n Name.
	 */
	public void setName(final String n) {
		this.name = n;
	}

	/**
	 * Get the duration of the encounter.
	 * @return Duration.
	 */
	public double getDurationMs() {
		return durationMs;
	}

	/**
	 * Set the duration of the encounter in millies.
	 * @param d Duration.
	 */
	public void setDurationMs(final double d) {
		this.durationMs = d;
	}
	
	/**
	 * Get the encounter duration minutes (rounded to floor).
	 * @return Minutes.
	 */
	public int getMinutes() {
		final int minuteInMillies = 60000;
		return (int) (this.durationMs / minuteInMillies);
	}
	
	/**
	 * Get the encounter duration seconds (rounded to floor).
	 * @return Seconds.
	 */
	public int getSeconds() {
		final int secondInMillies = 1000;
		final int minuteInMillies = 60000;
		return (int) ((this.durationMs - (this.getMinutes() * minuteInMillies)) 
				/ secondInMillies);
	}

}
